<?php

if (!defined('BASEPATH')) {
  exit('No direct script access allowed');
}

class Albums_load_more extends AUTH_Controller {

  /**
   * Albums Load More (Ajax)
   * 
   */
  public function index() {

    // Checking request type
    if ($this->is_post() && $this->is_ajax()) {

      // Getting inputs
      $type = $this->input->post('album_type', TRUE);
      $offset = (int) $this->input->post('album_offset', TRUE);

      // Getting album type
      if ($type == 'my') {
        $get_albums = $this->album_model->get_albums($this->current_user['user_id'], 12, $offset);
        $get_albums_count = $this->album_model->get_albums_count($this->current_user['user_id'], 12, $offset);
      } else {
        $get_albums = $this->album_model->get_albums(NULL, 12, $offset);
        $get_albums_count = $this->album_model->get_albums_count(NULL, 12, $offset);
      }

      $view_data = array();
      $view_data['albums_data'] = $get_albums['result'];
      $album_data = $this->load->view('ajax/albums_load_more', $view_data, TRUE);

      $has_more = 0;
      if ($type == 'my') {
        $get_more_albums = $this->album_model->get_albums($this->current_user['user_id'], 12, $offset + 12);
      } else {
        $get_more_albums = $this->album_model->get_albums(NULL, 12, $offset + 12);
      }
      if (!empty($get_more_albums['result'])) {
        $has_more = 1;
      }

      die(json_encode(array('status' => 1, 'data' => $album_data, 'has_more' => $has_more)));
    }

    // Redirect if invalid request
    redirect('albums');
  }

}

?>